package com.example.cuibo.i0;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
    public void xx() throws IOException{
        FileInputStream fis = new FileInputStream("aaa.text"); // 创建一个文件输入流文件 关联aaa.text 的文件
        int x = fis.read();// 每读取一次就会向后位移一位
        fis.close();
    }
    void xxxx()throws IOException{
        FileOutputStream out = new FileOutputStream("aaa.text",true); // true 是追加默认为NO
    }
    // 图片的复制
    void xxxxx()throws IOException{
        FileInputStream fis = new FileInputStream("a.jpeg");
        FileOutputStream fio = new FileOutputStream("b.jpeg");
    }

    // 有可能内存溢出
    void  xxxxxxx()throws IOException{
        FileInputStream fis = new FileInputStream(".mp3");
        FileOutputStream fio = new FileOutputStream("copy.mp3");
        byte[] arr = new byte[fis.available()];
        fis.read(arr);
        fio.write(arr);
        fis.close();
    }
    // 定义N个小数组拷贝文件
    void fisxxxx()throws IOException{
        FileInputStream fis = FileInputStream("aaa.text");
        byte[] arr = new byte[2];
        int x = fis.read(arr);  // 将文件的字节数据读取到字节数组中
        for (byte b:
                arr
             ) {

        }
        int y = fis.read(arr);
        for (byte b :
                arr) {

        }
        fis.close();
        System.out.print(x);
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
